<?php

	class Dbo
	{
		/*private $server_name = "";
		private $user_id = "";
		private $password = "";
		private $conn;
		*/
		
		private $server_name = "localhost";
		private $user_id = "root";
		private $password = NULL;
        private $db_name = "TutorService";
		private $conn;
		
		/*Class constructor*/
		public function __construct()
		{
			/*if($this->loadProperties("db_properties.xml") == false)
			{
				//properties are loaded fine
				echo "Application error has occured - properties";
			}
			else
			{
				//establish the connection
				$this->openDBConnection();
			}
			*/
			$this->openDBConnection();
			
		}
		
		/*Destructor*/
		public function __destruct()
		{
			$this->closeDBConnection();
			$this->server_name = "";
			$this->user_id = "";
			$this->password = "";
            $this->db_name = "";
		}
		
		/*A function that loads the properties from xml*/
		/*private function loadProperties($filename)
		{
			$success = false;
			
			if(file_exists($filename))
			{
				$xml = simplexml_load_file($filename);
				$this->server_name = (string)$xml->connection->server_name;
				$this->user_id = (string)$xml->connection->user_id;
				$this->password = (string)$xml->connection->password;
				$success = true;
			}
			
			return $success;
		}*/
		
		private function openDBConnection()
		{
			$this->conn = mysql_connect(
                $this->getServerName(),
                $this->getUserID(),
                $this->getPassword()
            );
            
			if(!$this->conn)
			{	die ('Could not connect: ' . mysql_error());
			}
            
            mysql_select_db($this->db_name, $this->conn);
		
        }
		
		/*A method to close the connection*/
		private function closeDBConnection()
		{
			mysql_close($this->conn);
		}
		
		/*A method that executes the sql statement against db*/
		public function runQuery($stmt)
		{
			$result = mysql_query($stmt);
			return $result;
		}
				
		private function getServerName()
		{
			return $this->server_name;
		}
		
		private function getUserID()
		{
			return $this->user_id;
		}
		
		private function getPassword()
		{
			return $this->password;
		}
	}
?>